/** ---------- 地图初始化 和 图层渲染 mixin  FOR Hmap2.3 ---------- */
import Vue from 'vue'
// import { ajaxCtx } from '@/api/config.js'
import MapMarker from '@/components/map/overflow/MapMarker.vue' // 标记
const MyMapMarker = Vue.extend(MapMarker)
let MAP_INSTANCE = null // 地图实例
const MAP_LAYERS = {} // { [layerName]: { type: 1, layer: xx, doms: [], level: 2 } } // type(1:Vector  2:Overlay); VECTOR无doms
const MAP_DEFAULT_LEVEL = 2 // 默认覆盖物（清除）级别
let MAP_ECHARTS_LAYER = null
export default {
  data () {
    return {
      mapIsReady: false // 地图是否准备就绪
    }
  },
  methods: {
    // ********** 地图 初始化&事件&通用方法 **********
    /**
     * 初始化地图
     * @param {String} sid dom id
     * @param {Object} config 配置参数
     * @param {Array} config.center 中心点 [lng, lat, 0]
     * @param {Number} config.zoom 层级
     * @param {String} config.crs 坐标系，默认4326
     * @param {Object} initLayer 初始化图层
     * @param {Object} initLayer.vector 矢量切片图层
     * @param {Object} initLayer.tms tms图层
     */
    mapInit (sid, config, initLayer) {
      // **** new hmap
      if (!config) { config = {} }
      const mapOptions = Object.assign({
        zoom: 16,
        maxLevel: 19,
        minLevel: 10
      }, config ?? {}, {
        crs: new hmap.proj.Crs(config?.crs ?? '4326'),
        center: this.mapGetCoordinate(config?.center || [112, 27])
      })
      // console.log('>>>>>>>>>> mapOptions：', mapOptions)
      const map = new hmap.Map(sid, mapOptions)
      // **** 矢量切片图层
      if (initLayer && initLayer.vector) {
        // initLayer.vector = { hvtUrl: ajaxCtx.hmap + '/hmap-server/hvt/', vOptions: { styleUrl: '', matrixOrigin: [-180, 90] }, layerName: '', zIndex:  }
        // 矢量切片图层 参数
        const vOptions = Object.assign({
          matrixOrigin: new hmap.basetype.Coordinate(-180, 90), // 切片原点
          dataFormat: 'hvt', // 切片格式
          labelOn: true, // 是否显示文字标注
          styleUrl: '', // './static/lib/hmap/style/white/mapStyle.json'
          isRTE: true
        }, initLayer.vector.vOptions)
        if (initLayer.vector.vOptions?.matrixOrigin) {
          vOptions.matrixOrigin = new hmap.basetype.Coordinate(initLayer.vector.vOptions.matrixOrigin[0], initLayer.vector.vOptions.matrixOrigin[1])
        }
        // console.log('>>>>>>>>>> vector vOptions：', vOptions)
        const vectilelayer = new hmap.layer.VectorTileLayer(initLayer.vector.layerName ?? '矢量切片图层', initLayer.vector.hvtUrl, vOptions)
        map.addLayer(vectilelayer, initLayer.vector.zIndex ?? 0)
      }
      // **** TMS图层
      if (initLayer && initLayer.tms) {
        // initLayer.tms = { tmsUrl: '', vOptions: { matrixOrigin: [-180, 90] }, layerName: '', zIndex:  }
        const vOptions = Object.assign({
          matrixOrigin: new hmap.basetype.Coordinate(-180, 90),
          dataFormat: 'png',
          dataMaxLevel: 18
        }, initLayer.tms.vOptions)
        if (initLayer.tms.vOptions?.matrixOrigin) {
          vOptions.matrixOrigin = new hmap.basetype.Coordinate(initLayer.tms.vOptions.matrixOrigin[0], initLayer.tms.vOptions.matrixOrigin[1])
        }
        // console.log('>>>>>>>>>> tms vOptions：', vOptions)
        const tileLayer = new hmap.layer.TMSLayer(initLayer.tms.layerName ?? 'TMS图层', initLayer.tms.tmsUrl, vOptions)
        map.addLayer(tileLayer, initLayer.tms.zIndex ?? 0) // 添加TMS图层并将图层z-index设置为0
      }
      // // 设置雾的颜色之前，需要先清空天空
      // map.setSkyImage(null)
      // // 定义Color对象
      // const color = new hmap.style.Color(44, 137, 221, 1.0)
      // // 设置雾的颜色
      // map.setFogColor(color)
      // // 重绘地图应用设置的雾的颜色
      // map.redraw()
      // 设置背景颜色
      map.setLandColor(new hmap.style.Color(238, 238, 238, 1))
      map.redraw()
      MAP_INSTANCE = map
      // MAP_INSTANCE.enableInteractive()
      this.mapIsReady = true
      this.mapEvents()
    },

    // ********** 地图 事件/交互 相关函数 **********
    // 地图事件
    mapEvents () {
      if (MAP_INSTANCE) {
        MAP_INSTANCE.event.register(EventType.MAPMOUSEEVENT_CLICK, (event) => {
          // console.log('>>>>>>>>>> event：', event)
          console.log('经纬度：', `${event.lonlat._x},${event.lonlat._y},${event.lonlat._z}`)
        })
        // MAPEVENT_EXTENTCHANGED
        let changeVal = null
        MAP_INSTANCE.event.addListener(EventType.MAPEVENT_EXTENTCHANGED, (event) => {
          changeVal && window.clearTimeout(changeVal)
          changeVal = window.setTimeout(() => {
            this.eventDataHandler({
              eventType: 'extentChanged'
            })
          }, 300)
        })
      }
    },
    // 设置层级
    mapSetZoom (val) {
      // MAP_INSTANCE.setZoom(val)
    },
    /**
     * 设置中心点、层级
     * @param {Object} data 数据
     * @param {Array} data.center [lng, lat, hgt] 经维度
     * @param {Double} data.move [lng+move, lat+move] 移动
     * @param {Number} data.zoom 层级
     */
    mapSetCenter (data) {
      const center = this.moveCenterLngLat(data)
      MAP_INSTANCE.setCenter(new hmap.basetype.Coordinate(center[0], center[1], center[2] || 0), data.zoom)
    },
    // 获取纬度的偏移 （为中心点服务）
    moveCenterLngLat (data) {
      if (data.move) {
        const extent = MAP_INSTANCE.getExtent()
        return [
          data.center[0] + (extent._right - extent._left) * data.move[0] ? data.move[0] : 0,
          data.center[1] + (extent._top - extent._bottom) * data.move[1] ? data.move[1] : 0,
          data.center[2] || 0
        ]
      }
      return data.center
    },
    getExtentInfo (callback) {
      callback(null, {
        extent: MAP_INSTANCE.getExtent(), // {_left: 112.65041015625, _bottom: 28.004605712890626, _right: 113.30958984375, _top: 28.375394287109376}
        viewport: MAP_INSTANCE.getViewport(), // [0, 0, 1920, 1080]
        zoom: MAP_INSTANCE.getZoom() // 12
      })
    },
    // ********** 地图 图层相关函数 **********
    /**
     * [000001] 地图标记详情
     * @param {Object} data 数据
     */
    mapMarkerDetail (data) {
    },
    /**
     * [000010] 标记
     * @param {Object} data 数据
     * @param {Nmuber} data.level 级别，|| MAP_DEFAULT_LEVEL
     * @param {String} data.layerName 矢量图层名称
     * @param {Boolean} data.layerNoClear 不清除layerName数据（即默认清除layerName数据）
     * @param {Boolean} data.setHeight 如果是三维地图，是否需要设置高程，默认为false
     * @param {Object} data.labelOptions {icon: {}, textSymbol: {}} 标签配置数据 (为null则不用icon/textSymbol, 启用默认icon/textSymbol则为{})
     * @param {Function} data.click 点击回调函数
     * @param {Array} data.list 标记数据
     *  [{ title: '', position: [x,y,z]}, {...}], ... }]
     */
    mapMarkers (data) {
      // console.log('>>>>>>>>>> mapMarkers：', data)
      const _layerObj = this.mapLayerHandler(1, data) // 图层类型 1:Vector  2:Overlay
      if (!_layerObj || !data.list || data.list.length <= 0) return false
      this.mapVectorMarker(_layerObj.layer, data.list, data.labelOptions, data.click)
    },
    /**
     * Vector图层 标记
     * @param {Object} layer 图层
     * @param {Array} data.list 标签/拾取模型 数据
     *  [{ title: '', position: [x,y,z]}, {...}], paths: [[x,y,z], [x,y,z]], [...]] }]
     * @param {Object} labelOptions icon & textSymbol 标签配置数据 (为null则不用icon/textSymbol, 启用默认icon/textSymbol则为{})
     * @param {Function} _click 点击回调函数
     */
    mapVectorMarker (layer, list, labelOptions, _click) {
      const features = []
      const _markerSymbols = []
      if (labelOptions?.icon) {
        _markerSymbols.push(new hmap.style.Icon(Object.assign({
          imgSrc: './static/images/map/map_building.png',
          anchor: [0.5, 0.9], // 锚点位置。eg：默认将锚点定为图标的中心点，即[0.5,0.5]。图标的左上角为[0,0],右下角为[1,1]。单位为1。
          size: new hmap.basetype.Size(60, 72)
        }, labelOptions.icon)))
      }
      list.map(item => {
        const title = item.title ?? ' '
        const _coord = this.mapGetCoordinate(item.position)
        if (_coord) {
          const feature = new hmap.feature.Vector(new hmap.geom.Point(_coord))
          const _textSymbols = []
          if (labelOptions?.textSymbol) {
            _textSymbols.push(new hmap.style.TextSymbol(Object.assign({
              text: title,
              fontColor: new hmap.style.Color(255, 142, 1, 1),
              fontSize: 20,
              fontWeight: 'bold',
              haloWidth: 1,
              haloColor: new hmap.style.Color(255, 255, 255, 1),
              offset: new hmap.basetype.Offset(0, -80, 0),
              rowTextCount: 10
            }, labelOptions.textSymbol)))
          }
          if (item.labelOptions.icon) { // 数据自定义图标
            feature.setStyle(new hmap.style.Style({
              markerSymbols: [new hmap.style.Icon(item.labelOptions.icon)],
              textSymbols: _textSymbols
            }))
          } else {
            feature.setStyle(new hmap.style.Style({
              markerSymbols: _markerSymbols,
              textSymbols: _textSymbols
            }))
          }
          if (_click) {
            feature.onClick((event) => {
              // event.feature 可以取到要素本身
              _click(event, item)
            })
          }
          // feature.setAttributes({name:'卡口', age:14})
          features.push(feature)
        }
      })
      layer.addFeatures(features)
    },
    /**
     * [000011] OverlayLayer 标记 html (MapMarker)
     * @param {Object} data 数据
     * @param {Nmuber} data.level 级别，|| MAP_DEFAULT_LEVEL
     * @param {String} data.layerName 矢量图层名称
     * @param {Boolean} data.layerNoClear 不清除layerName数据（即默认清除layerName数据）
     * @param {String} data.component 组件
     * @param {Boolean} data.setHeight 如果是三维地图，是否需要设置高程，默认为false
     * @param {Array} data.list 标记数据
     *  data.list[n].position=[x, y, z]
     */
    mapMarkersOverlay (data) {
      // if (data && !data.layerName) { data.layerName = 'Overlay_Resources' }
      const _layerObj = this.mapLayerHandler(2, data) // 2 overlay
      if (!_layerObj || !data.list || data.list.length <= 0) return false
      data.list.map(item => {
        if (item.position) {
          const panelDom = new MyMapMarker({
            data: {
              component: data.component,
              data: item
            },
            methods: {
              // 点击 click 触发的方法
              clickAction () {
                if (data.click) {
                  data.click(this.data)
                }
              }
            }
          })
          const simplePopup = new hmap.overlay.SimplePopup({
            location: this.mapGetCoordinate(item.position, data.setHeight),
            // editable: true,
            // zIndex: 2000,
            element: panelDom.$mount().$el
          })
          _layerObj.layer.addOverlay(simplePopup)
          // 将Marker实例根据图层放入容器
          _layerObj.doms.push(panelDom)
        }
      })
      // MAP_LAYERS[data.layerName] = _layerObj
    },
    /**
     * [000020] 多边形
     * @param {Object} data 数据
     * @param {Nmuber} data.level 级别，|| MAP_DEFAULT_LEVEL
     * @param {String} data.layerName 矢量图层名称
     * @param {Boolean} data.layerNoClear 不清除layerName数据（即默认清除layerName数据）
     * @param {Object} data.options (多边形)配置数据
     *  { fillColor: [0, 255, 0, 0.5], lineColor: [0, 255, 0, 0.5], width: 5 } // lineStyle: solid/dash dashRatio: [2,1,3,2]
     * @param {Array} data.list 数据
     *  [{ coordinates: [[x,y,z], [x,y,z], ..., [x,y,z]], ?options: {fillColor/lineColor/lineWidth} }]
     */
    mapPolygons (data) {
      const _layerObj = this.mapLayerHandler(1, data) // 1 vector
      if (!_layerObj || !data.list || data.list.length <= 0) return false
      const polygonFeatures = []
      // 多边形样式
      const polygonFillColor = this.getFillColor(data.options) // 定义面的填充色
      const lineSymbol = this.getLineSymbol(data.options) // 定义面的边框颜色和边框宽度
      const polygonStyle = new hmap.style.Style({
        fillSymbols: [polygonFillColor],
        lineSymbols: [lineSymbol]
      })
      for (let i = 0; i < data.list.length; i++) {
        // 添加一个polygon几何体  Coordinate——>Point——>LinearRing——>Polygon
        const obj = data.list[i]
        const points = []
        for (let j = 0; j < obj.coordinates.length; j++) {
          const arr = obj.coordinates[j]
          points.push(new hmap.geom.Point(new hmap.basetype.Coordinate(arr[0], arr[1])))
        }
        const linearRing = new hmap.geom.LinearRing(points)
        const polygon = new hmap.geom.Polygon([linearRing])
        let subPolygonStyle = polygonStyle
        if (obj.options) { // 如果子集存在配置，则启用子集的
          const subPolygonFillColor = this.getFillColor(obj.options) // 定义面的填充色
          const subLineSymbol = this.getLineSymbol(obj.options) // 定义面的边框颜色和边框宽度
          subPolygonStyle = new hmap.style.Style({
            fillSymbols: [subPolygonFillColor],
            lineSymbols: [subLineSymbol]
          })
        }
        polygonFeatures.push(new hmap.feature.Vector((polygon), {}, subPolygonStyle))
      }
      _layerObj.layer.addFeatures(polygonFeatures)
    },
    // 获取面的颜色
    getFillColor (options) {
      let polygonFillColor = new hmap.style.ColorFill(new hmap.style.Color(0, 255, 0, 0.5)) // 定义面的填充色
      if (options?.fillColor?.length > 3) {
        polygonFillColor = new hmap.style.ColorFill(new hmap.style.Color(options.fillColor[0], options.fillColor[1], options.fillColor[2], options.fillColor[3]))
      }
      return polygonFillColor
    },
    // 获取边框样式
    getLineSymbol (options) {
      // 定义面的边框颜色和边框宽度
      const lineStyle = Object.assign({
        color: new hmap.style.Color(255, 0, 0, 0.5),
        width: 5
      }, options || {})
      if (options?.lineColor?.length > 3) {
        lineStyle.color = new hmap.style.Color(options.lineColor[0], options.lineColor[1], options.lineColor[2], options.lineColor[3])
      }
      return new hmap.style.LineSymbol(lineStyle)
    },
    /**
     * [000030] 折线
     * @param {Object} data 数据
     * @param {Nmuber} data.level 级别，|| MAP_DEFAULT_LEVEL
     * @param {String} data.layerName 矢量图层名称
     * @param {Boolean} data.layerNoClear 不清除layerName数据（即默认清除layerName数据）
     * @param {Array} data.list 数据
     *  [{ coordinates: [[x,y,z], [x,y,z], ..., [x,y,z]] }]
     */
    mapPolylines (data) {
      const _layerObj = this.mapLayerHandler(1, data) // 1 vector
      if (!_layerObj) return false
    },
    // 聚合函数的回调
    clusterCallback (event) {
      console.log('经纬度：', `${event.lonlat._x},${event.lonlat._y},${event.lonlat._z}`)
      const mapPixel = event.mapPixel
      const results = MAP_INSTANCE.detectFeaturesAtPixel(mapPixel, ['Cluster_CityRes_fires'])
      if (results) {
        const object = results[0]
        if (object && !object._attributes.clusterCount) {
          console.log('选中的是 非聚合节点')
          if (this.fireClick) {
            this.fireClick(event, object._attributes)
          }
        }
      }
    },
    /**
     * [001010] 聚合层
     * @param {Object} data 数据
     */
    mapLayerCluster (data) {
      if (data.list && data.list.length > 0) {
        let clusterLayer = MAP_LAYERS[data.layerName]
        if (!clusterLayer) { // 如果之前没有创建图层，则需要创建图层
          const clusterStyle = new hmap.style.Style({ markerSymbols: [data.labelOptions.clusterMarker], textSymbols: [data.labelOptions.clusterText] })

          clusterLayer = new hmap.layer.ClusterLayer(data.layerName, {
            opacity: 1.0,
            enableHashCode: true,
            disableClusteringAtZoom: 18,
            isRTE: true,
            clusterStyle: clusterStyle,
            minClusterNum: 1 // 同一个聚合网格中的要素数量达到3才会发生聚合
          })
          MAP_INSTANCE.addLayer(clusterLayer)
          MAP_LAYERS[data.layerName] = clusterLayer
          MAP_INSTANCE.event.register(EventType.MAPMOUSEEVENT_CLICK, function (event) {
            console.log('经纬度：', `${event.lonlat._x},${event.lonlat._y},${event.lonlat._z}`)
            const mapPixel = event.mapPixel
            const results = MAP_INSTANCE.detectFeaturesAtPixel(mapPixel, [data.layerName])
            if (results) {
              const object = results[0]
              if (object && !object._attributes.clusterCount) {
                console.log('选中的是 非聚合节点')
                if (data.click) {
                  data.click(event, object._attributes)
                }
              }
            }
          })
        }
        clusterLayer.removeAllFeatures() // 清除所有的元素
        const features = []
        // 聚合点位的信息
        const positionArr = data.list
        for (let i = 0; i < positionArr.length; i++) {
          const position = positionArr[i].position
          const feature = new hmap.feature.Vector(new hmap.geom.Point(new hmap.basetype.Coordinate(position[0], position[1], 0)))
          feature.setStyle(new hmap.style.Style({
            markerSymbols: [data.labelOptions.onlyMarker]
          }))
          feature.setAttributes(positionArr[i])
          features.push(feature)
        }
        if (features) {
          clusterLayer.addFeatures(features)
        }
      } else { // 没有数据的 逻辑情况
        const clusterLayer = MAP_LAYERS[data.layerName]
        if (clusterLayer) { // 如果创建了图层，则移除所有的 图标数据
          clusterLayer.removeAllFeatures()
        }
        if (data.clearAction) {
          data.clearAction()
        }
      }
    },
    /**
     * [002010] 热力图
     * @param {Object} data 数据
     * @param {Nmuber} data.level 级别，|| MAP_DEFAULT_LEVEL
     * @param {Array} data.list 数据
     *  [[{"coord":[120.14322240845,30.236064370321],"elevation":21}, {"coord":[120.14280555506,30.23633761213],"elevation":5},...]]
     */
    mapHeatmap (data) {
      // console.log('>>>>>>>>>>mapHeatmap data：', data)
      if (data.list && data.list.length > 0) {
        const points = [].concat.apply([], data.list.map(function (track) {
          return track.map(function (seg) {
            // 数据纠偏
            // const x = seg.coord[0] - 0.01115
            // const y = seg.coord[1] - 0.00335
            const x = seg.coord[0]
            const y = seg.coord[1]
            return [x, y].concat([1])
          })
        }))
        const option = {
          HMap: {
            roam: 'true'
          },
          coordinateSystem: 'HMap',
          visualMap: {
            show: false,
            top: 'top',
            min: 0,
            max: 5,
            seriesIndex: 0,
            calculable: true,
            inRange: {
              color: ['blue', 'blue', 'green', 'yellow', 'red']
            }
          },
          // title: {
          //   text: '热力图',
          //   left: 'center',
          //   textStyle: {
          //     color: '#111'
          //   }
          // },
          series: [{
            type: 'heatmap',
            coordinateSystem: 'HMap',
            data: points,
            pointSize: 5,
            blurSize: 6
          }]
        }
        if (MAP_ECHARTS_LAYER) {
          MAP_ECHARTS_LAYER.chart.clear() // 图层已经存在则先clear
        } else {
          MAP_ECHARTS_LAYER = new EchartsLayer(MAP_INSTANCE)
        }
        MAP_ECHARTS_LAYER.chart.setOption(option)
      } else if (MAP_ECHARTS_LAYER) {
        // echartslayer.chart.clear()
        MAP_ECHARTS_LAYER.chart.clear()
        // ECHARTS_LAYER_HEATMAP = null
      }
    },
    /**
     * 图层处理
     * @param {Nmuber} type 图层类型 1:Vector  2:Overlay
     * @param {Object} data 数据 { level: 2, layerName: '', layerNoClear: , zIndex:  }
     */
    mapLayerHandler (type, data) {
      if (!data.layerName) {
        console.log('图层名称为空，', data)
        return null
      }
      let _layerObj = MAP_LAYERS[data.layerName] // 根据layerName从图层容器中获取图层
      if (_layerObj) {
        // _layerObj.layer && _layerObj.layer.setVisibility(true)
        if (!data.layerNoClear) {
          // 图层存在，且未指定不清空图层，则清空图层
          this.mapClearWithLayer(_layerObj)
        }
      } else {
        // 图层不存在则新建图层
        _layerObj = {}
        _layerObj.type = type
        _layerObj.level = data.level ?? MAP_DEFAULT_LEVEL
        if (type === 1) { // Vector
          const _cfg = { isRTE: true }
          // _cfg.enableHashCode = true
          if (data.click) {
            // map enableInteractive() && layer  enableHashCode: true
            _cfg.enableHashCode = true
            MAP_INSTANCE.enableInteractive()
          }
          _layerObj.layer = new hmap.layer.VectorLayer(data.layerName, _cfg)
        } else if (type === 2) { // overlay
          _layerObj.layer = new hmap.layer.OverlayLayer(data.layerName)
          _layerObj.doms = []
        }
        // MAP_INSTANCE.addLayer(_layerObj.layer, data.zIndex ? data.zIndex : null) // 为毛zIndex不起作用????
        MAP_INSTANCE.addLayer(_layerObj.layer)
        if (data.zIndex) {
          if (type === 1) { // Vector
            _layerObj.layer.setZIndex(data.zIndex)
          } else if (type === 2) { // overlay
            _layerObj.layer.setLayerZIndex(data.zIndex)
          }
        }
        MAP_LAYERS[data.layerName] = _layerObj
      }
      // console.log('>>>>>>>>>>  MAP_LAYERS ：', MAP_LAYERS)
      return MAP_LAYERS[data.layerName]
    },

    /**
     * 清空图层 清空数据&doms
     * @param {Object} layerObj 图层对象{ type: 1, layer: layer, doms[], level: 2 } type 图层类型 1:Vector  2:Overlay
     */
    mapClearWithLayer (layerObj) {
      // console.log('>>>>>>>>>> mapClearWithLayer layerObj：', layerObj)
      if (layerObj.doms && layerObj.doms.length > 0) {
        // 清除doms
        layerObj.doms.map((item) => {
          item.$destroy()
        })
        layerObj.doms = []
      }
      if (layerObj.type === 1 && layerObj.layer) { // Vector
        layerObj.layer.removeAllFeatures()
      } else if (layerObj.type === 2 && layerObj.layer) { // overlay
        // console.log('>>>>>>>>>> layerObj：', layerObj)
        // layerObj.layer.setVisibility(false)
        layerObj.layer.removeAllOverlays()
      }
    },

    /**
     * 清除地图
     * @param {Nmuber} clearLevel 清楚级别，默认为2(MAP_DEFAULT_LEVEL)
     */
    mapClear (clearLevel) {
      if (clearLevel === null || clearLevel === undefined) {
        // 默认清除级别
        clearLevel = MAP_DEFAULT_LEVEL
      }
      // clearLevel <= 0 不清除
      if (!MAP_INSTANCE || clearLevel <= 0) { return false }
      for (const i in MAP_LAYERS) {
        if (MAP_LAYERS[i].level <= clearLevel) {
          // console.log('>>>>>>>>>> mapClear：', MAP_LAYERS[i])
          // 清除所有级别小于clearLevel的图层
          this.mapClearWithLayer(MAP_LAYERS[i])
        }
      }
    },

    /**
     * 获取Coordinate（自动调用坐标处理器）   **** 此函数的执行需要在三维地图 加载完成之后，不然计算不出来
     * @param {Array} position 数据 [x, y, z]
     * @param {Boolean} setHeight 如果是三维地图，是否需要设置高程，默认为false
     */
    mapGetCoordinate (position, setHeight = false) {
      let _coord = null
      if (position && position[0] >= 0 && position[1] >= 0) {
        // const _pst = this.mapCoordinateHandler([position])[0]
        this.mapCoordinateHandler([position])
        _coord = new hmap.basetype.Coordinate(position[0], position[1], position[2] ?? 0)
        if (setHeight) {
          // 获取指定坐标点位，在地图三维场景中的实际高程。当传入的坐标点经纬度，不在地图范围内时，会返回null
          const _z = MAP_INSTANCE.getHeightByCoord(_coord)
          if (_z != null) {
            _coord.setOrdinate('Z', _z)
          }
        }
      }
      return _coord
    },
    /**
     * 坐标处理器 --->>> 如果需要转换坐标则可在这里进行统一转换
     * @param {Array} positions 坐标 [[120.14280555506, 30.23633761213, 0], ...]
     */
    mapCoordinateHandler (positions) {
      // positions.map(item => {
      //   // 转换
      //   item = [...item]
      // })
    }
  }
}
